let ajax = getApp().globalData.ajax;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isAllInit: true,
    onlineList: [],
    skillInfo: {
      game: [
        { title: '绝地求生', status_res: '需审核' },
        { title: '王者荣耀', status_res: '需审核' }
      ],
      emotion: [
        { title: '情感发泄', status_res: '需审核' },
        { title: '情感咨询', status_res: '需审核' }
      ],
    }
  },

  toGameSkill (e) {
    let status = e.target.dataset.skill.status
    if (status === 'INIT' || status === 'DENIED') {
      let skill = JSON.stringify(e.target.dataset.skill);
      wx.navigateTo({
        url: `../gameSkill/gameSkill?skill=${skill}`,
      })
    }
  },
  toEmotionSkill (e) {
    let status = e.target.dataset.skill.status
    if (status === 'INIT' || status === 'DENIED') {
      let skill = JSON.stringify(e.target.dataset.skill);
      wx.navigateTo({
        url: `../emotionSkill/emotionSkill?skill=${skill}`,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getStatus();
  },

  getStatus () {
    ajax('seller/allskill', { token: wx.getStorageSync('Cookie') }).then(res => {
      let skillList = res.data || [];

      //如果状态都为Init 则表示所有资质都未通过或者申请
      let isAllInit = skillList.every(item => item.status == 'INIT');

      //通过的资质显示
      let onlineList = [],
        skillInfo = {
          game: [],
          emotion: [],
        }
      skillList.forEach(item => {
        switch (item.status) {
          case 'INIT':
            item.status_res = '需审核'
            item.status_class = 'INIT'
            break;
          case 'DENIED':
            item.status_res = '需审核'
            item.status_class = 'DENIED'
            break;
          case 'ONLINE':
            item.status_res = '已审核'
            item.status_class = 'ONLINE'
            break;
          case 'OFFLINE':
            item.status_res = '已下线'
            item.status_class = 'OFFLINE'
            break;
          case 'FORBIDDEN':
            item.status_res = '已封禁	'
            item.status_class = 'FORBIDDEN'
            break;
        }
        if (item.status == 'ONLINE') {
          onlineList.push(item.title);
        }
        if (item.category == '游戏陪练') {
          skillInfo.game.push(item);
        } else {
          skillInfo.emotion.push(item);
        }

      })


      this.setData({ isAllInit, onlineList, skillInfo })

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})